<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>

<div id="app">
    <input type="text" v-model="n1">
    <select v-model="opt">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
    </select>
    <input type="text" v-model="n2">
    <input type="button" @click="calc" value="=">
    <input type="text" v-model="result">

</div>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            n1:0,
            n2:0,
            result:0,
            opt: '+'
        },
        methods: {
            calc() {
                // 第一种方式switch(this.opt), 推荐
                // 第二种方式，不推荐，使用eval
                var str = 'parseInt(this.n1)' + this.opt + 'parseInt(this.n2)';
                this.result = eval(str);
            }
        }
    })
</script>
</body>
</html>
